home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
bars.exe
/
BARS.C
< prev
Wrap
C/C++ Source or Header
|
1992-02-29
|
11KB
|
448 lines
/*
** BAR GRAPHS
**
** was written in Turbo C++ in September, 1991. This was
** my fourth program I had ever written, and was inspired
** by a couple of good books on GRAPHICS PROGRAMMING IN C++.
**
** Leafing through the Library Reference to Turbo C++, I
** had frequently encountered graphic functions. Not fully
** understanding what they did and how they interacted,
** I never used them.
**
** Now that I am more than comfortable with Graphic programming,
** I am uploading this code to encourage more people to
** enthusiastically learn graphics.
**
** Compile with:
**
**
** TCC -MS BAR.C EGAVGA.OBJ CGA.OBJ GRAPHICS.LIB
**
** See your reference manual concerning how to transform
** CGA.LIB and EGAVGA.LIB into the objective files.
**
** (or if you REALLY cannot figure it out, drop me a line ... )
**
**
**
**
** Dave Smith
** CIS 71441,2723
**
*/
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dir.h>
#include <dos.h>
/* THIS "DEFINE" SAVES MY LIFE LATER ... YOU'LL SEE */
#define DUDE if(strstr(dta.ff_name,
void getfiles(void);
void show(char *stuff, int w, int w2);
void DRAWIT(int start, int minus);
/* These should be re-done into a large integer array, but */
/* for ease-of-reading purposes, I have left them as separate */
/* entities. */
int zip,arj,arcs,zoo,pak,lzh,exe,bat,com,doc,txt,hlp,dat,tmp,log,eng,man;
int bas,pas,a86,asms,obj,c,h,bak,tch,map,sys,dsk,set,cfg,prn,pcx,gif,tif;
int mac,wpg,img,fra,cit,tga,bmp,ini,pif,grp,fon,dll,drv,mod, inf, bottom;
int onlyhere=1;
char origdir[30];
main(int argc, char *argv[])
{
int gdriver = DETECT, gmode, errorcode;
int farright, i, a, b, xmult, xdiv, ymult, ydiv;
getcwd(origdir, 30);
/* Parse the command line and find out if we should change
** directories or stay here, or leak into subdirectories also
*/
if(argc==1) onlyhere=1;
strupr(argv[1]);
if(strstr(argv[1], "/S")){ onlyhere=0; chdir("\\"); }
if(strstr(argv[1], "\\")) chdir(argv[1]);
/* Set the integers to ZERO. And for those who continue to tell
** me that initializing an integer automatically sets it to ZERO,
** YOU ARE WRONG ! I get stuck with -1 as a constant.
*/
zip=arj=arcs=zoo=pak=lzh=exe=bat=com=doc=txt=hlp=dat=tmp=log=eng=man=0;
bas=pas=a86=asms=obj=c=h=bak=tch=map=sys=dsk=set=cfg=prn=0;
pcx=gif=tif=mac=wpg=img=fra=cit=tga=0;
bmp=ini=pif=grp=fon=dll=drv=mod=inf=0;
/* INITIALIZE GRAPHICS, CALL VGA, EGA, & CGA DRIVERS */
if(registerbgidriver(EGAVGA_driver) < 0) exit(1);
if(registerbgidriver(CGA_driver) < 0) exit(1);
initgraph(&gdriver, &gmode, "");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
farright=getmaxx(); /* OBTAIN MAXIMUM X AND Y COORDINATES */
bottom = getmaxy();
setcolor(10); /* Set the color to green ! */
/* DRAW MY LITTLE INTRODUCTION SCREEN */
line(5, 5, 5, bottom-30);
line(5,bottom-30, farright-40,bottom-30);
line(farright-40, bottom-30, farright-40,5);
line(73, bottom-30, 73, 5);
line(5, 5, farright-40, 5);
line(113, bottom-30, 113, 5);
line(163, bottom-30, 163, 5);
line(193, bottom-30, 193, 5);
line(293, bottom-30, 293, 5);
line(343, bottom-30, 343, 5);
line(433, bottom-30, 433, 5);
/* AND MY AXIS */
b=0;
for(i=bottom-30; i>25; i-=50){
setcolor(10);
line(5, i, farright-40, i);
moveto(farright-26, i);
setcolor(14);
if(b==0) outtext ("0" );
if(b==1) outtext ("25");
if(b==2) outtext ("50");
if(b==3) outtext ("75");
if(b==4) outtext("100");
if(b==5) outtext("125");
if(b==6) outtext("150");
if(b==7) outtext("175");
if(b==8) outtext("200");
b++;
}
/* AND THE INTRODUCTION SCREEN */
setcolor(9);
outtextxy(535,bottom-290,"Dave's");
outtextxy(535,bottom-270,"File");
setcolor(8);
outtextxy(535,bottom-250,"Usage");
setcolor(9);
outtextxy(535,bottom-230,"Graph");
setcolor(11);
outtextxy(530,bottom-210,"(c) 1992");
getfiles(); /* GETFILES() GRABS THE FILES AND COMPARES THEIR */
/* EXTENSIONS */
/* DRAW DIFFERENT BAR GRAPHS DEPENDENT UPON WHICH FILES
* WE FIND IN EACH CATEGORY
*/
setcolor(3);
setfillstyle(1, 1);
DRAWIT(15, zip);
DRAWIT(25, arcs);
DRAWIT(35, zoo);
DRAWIT(45, pak);
DRAWIT(55, arj);
DRAWIT(65, lzh);
setcolor(11);
setfillstyle(2, 2);
DRAWIT(75, exe);
DRAWIT(85, bat);
DRAWIT(95, com);
DRAWIT(105, bat);
setcolor(15);
setfillstyle(3, 3);
DRAWIT(115, doc);
DRAWIT(125, txt);
DRAWIT(135, hlp);
DRAWIT(145, log);
DRAWIT(155, man);
setcolor(9);
setfillstyle(4, 4);
DRAWIT(165, eng);
DRAWIT(175, dat);
DRAWIT(185, tmp);
setcolor(13);
setfillstyle(10, 5);
DRAWIT(195, bas);
DRAWIT(205, pas);
DRAWIT(215, a86);
DRAWIT(225, asms);
DRAWIT(235, obj);
DRAWIT(245, c);
DRAWIT(255, h);
DRAWIT(265, bak);
DRAWIT(275, tch);
DRAWIT(285, map);
setcolor(7);
setfillstyle(11, 6);
DRAWIT(295, sys);
DRAWIT(305, dsk);
DRAWIT(315, set);
DRAWIT(325, cfg);
DRAWIT(335, prn);
setcolor(6);
setfillstyle(7, 7);
DRAWIT(345, pcx);
DRAWIT(355, gif);
DRAWIT(365, tif);
DRAWIT(375, mac);
DRAWIT(385, wpg);
DRAWIT(395, img);
DRAWIT(405, fra);
DRAWIT(415, cit);
DRAWIT(425, tga);
setcolor(11);
setfillstyle(8, 8);
DRAWIT(435, bmp);
DRAWIT(445, ini);
DRAWIT(455, pif);
DRAWIT(465, grp);
DRAWIT(475, fon);
DRAWIT(485, dll);
DRAWIT(495, drv);
DRAWIT(505, mod);
DRAWIT(515, inf);
settextstyle(2, 0, 1);
/* NOW DRAW BOTTOM LABELS FOR FILES */
setcolor(3 ); outtextxy(15, bottom-25, "COMPR");
setcolor(11); outtextxy(75, bottom-25, "EXEC");
setcolor(15); outtextxy(115, bottom-25, "DOCS");
setcolor(9 ); outtextxy(165, bottom-25, "DAT");
setcolor(13); outtextxy(195, bottom-25, "PROGRAMMING");
setcolor(7 ); outtextxy(295, bottom-25, "SYSTEM");
setcolor(6 ); outtextxy(352, bottom-25, "GRAPHICS");
setcolor(11); outtextxy(445, bottom-25, "WINDOWS");
/** NOW LABEL EACH BAR GRAPH, THEN PLACE THE NUMBER OF FILES THAT
** ARE CONTAINED IN THE CATEGORIES ABOVE THE BAR. THIS TECHNIQUE
** IS RATHER TRICKY, SINCE WE MIGHT GO SO FAR UP THAT THE
** BAR AND WORD ARE OFF THE SCREEN !
*/
if(zip>10) show("zip", zip, 15 );
if(arcs>10)show("arc", arcs,25 );
if(zoo>10) show("zoo", zoo, 35 );
if(pak>10) show("pak", pak, 45 );
if(arj>10) show("arj", arj, 55 );
if(lzh>10) show("lzh", lzh, 65 );
if(exe>10) show("exe", exe, 75 );
if(bat>10) show("bat", bat, 85 );
if(com>10) show("com", com, 95 );
if(doc>10) show("doc", doc, 115);
if(txt>10) show("txt", txt, 125);
if(hlp>10) show("hlp", hlp, 135);
if(log>10) show("log", log, 145);
if(man>10) show("man", man, 155);
if(eng>10) show("eng", eng, 165);
if(dat>10) show("dat", dat, 175);
if(tmp>10) show("tmp", tmp, 185);
if(bas>10) show("bas", bas, 195);
if(pas>10) show("pas", pas, 205);
if(a86>10) show("a86", a86, 215);
if(asms>10)show("asm", asms,225);
if(obj>10) show("obj", obj, 235);
if(c> 10) show("c" , c , 245);
if(h> 10) show("h" , h , 255);
if(bak>10) show("bak", bak, 265);
if(tch>10) show("tch", tch, 275);
if(map>10) show("map", map, 285);
if(sys>10) show("sys", sys, 295);
if(dsk>10) show("dsk", dsk, 305);
if(set>10) show("set", set, 315);
if(cfg>10) show("cfg", cfg, 325);
if(prn>10) show("prn", prn, 335);
if(pcx>10) show("pcx", pcx, 345);
if(gif>10) show("gif", gif, 355);
if(tif>10) show("tif", tif, 365);
if(img>10) show("img", img, 395);
if(fra>10) show("fra", fra, 405);
if(bmp>10) show("bmp", bmp, 435);
if(ini>10) show("ini", ini, 445);
if(pif>10) show("pif", pif, 455);
if(grp>10) show("grp", grp, 465);
if(fon>10) show("fon", fon, 475);
getch();
closegraph();
chdir(origdir);
exit(0);
}
/* THIS FUNCTION FI